#include <cstdlib>
#include <iostream>
#include <dml/dml.h>
#include <string.h>
#include <extensions/gldml.h>
#include "engine.h"

#define width 1024
#define height 768

s_mesh modelbump;
s_bitmap texturebump, texture;
int texturebumpid;
int textureid;

void DML_main()
{
    DML_InitOpenGL(width,height,"opengl");
    DML_settitle("Opengl Shaders");
    
    //Laad model bump in
    LoadMesh("player.obj",&modelbump);
    DML_LoadBitmap("rock.bmp",&texture);
    DML_LoadBitmap("rockNormal.bmp",&texturebump);
    
    
    
    //init
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);

	// For lighting, pull our material colors from the vertex color...
    glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );
    glEnable( GL_COLOR_MATERIAL );

    // Set light 0 to be a pure white point light
    GLfloat diffuse_light0[]  = { 1.0f, 1.0f,  1.0f, 1.0f };
    GLfloat position_light0[]  = { 1.0f, 1.0f,  1.0f, 1.0f };
    glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse_light0 );
    glLightfv( GL_LIGHT0, GL_POSITION, position_light0 );
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );

    // Enable some dim, gray ambient lighting so objects that are not lit
    // by the other lights are not completely black.
    GLfloat ambient_lightModel[] = { 0.2f, 0.2f, 0.2f, 0.2f };
    glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient_lightModel );


    //set videowindow
    DML_video_setmode(640,480,32,DML_BLITTERMODE_STD32 | DML_VIDEO_NONE);
    
    do
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
        //Set projection matrix (mode opengl)
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glViewport(0, 0, width, height);

        glPerspective(45,1.0f,1,1000);

        //look
	    glLookAt(0.0f, 0.0f, 0.0f, 1.0f,1.0f,1.0f);
	    
	    SwapBuffers(hdc);
    }while (1);
}
